﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GDIT.Base.PageBaseHelper;
using GDIT.BLL;
using GDIT.Model;
using DevExpress.Xpo;

namespace GDIT
{
    public partial class index1 : System.Web.UI.Page
    {

        private BMainMenus main = null;
        private BDetailMenus detail = null;
        private BBulletinArticle bulletin = null;
        private BCollegeInformationArticle college = null;
        private BPicInfo pic = null;
        private BLinkInfo link = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    //调用方法判断该用户IP是否属于内网。
                    string userIP = PageBase.GetClientIP();
                    BInternalIP internalIP = new BInternalIP();
                    bool result = internalIP.SelectInternalIP(userIP);
                    Session["Internal"] = result;
                    if (result == true)
                    {
                        BindInternalArcticle();
                        BindMainMenus();
                        BindDetailMenus();
                        BindChangeNews();
                        BindPicLink();
                        BindLink();
                    }
                    else
                    {
                        BindArticle();
                        BindMainMenus();
                        BindDetailMenus();
                        BindChangeNews();
                        BindPicLink();
                        BindLink();
                    }
                }
            }
            catch (Exception ex)
            {
                PageBase.MessageBoxShow("登陆信息错误，请仔细核对登陆信息！", Page);
            }
        }

        private void BindInternalArcticle()//绑定内部文章
        {
            bulletin = new BBulletinArticle ();
            college = new BCollegeInformationArticle ();
            this.BulletinRepeater.DataSource = bulletin.SelectInternalBulletinByIndex();
            this.CollegeRepeater.DataSource = college.SelectInternalCollege();
            this.BulletinRepeater.DataBind();
            this.CollegeRepeater.DataBind();
        }

        private void BindArticle()//绑定文章
        {
            bulletin = new BBulletinArticle ();
            this.BulletinRepeater.DataSource = bulletin.SelectBulletinByIndex();
            this.BulletinRepeater.DataBind();
            college = new BCollegeInformationArticle();
            this.CollegeRepeater.DataSource = college.SelectCollege();
            this.CollegeRepeater.DataBind();
        }

        private void BindMainMenus()//绑定主菜单
        {
            main = new BMainMenus ();
            this.rptFirst.DataSource = main.SelectMainMenus();
            this.rptFirst.DataBind();
        }

        private void BindDetailMenus()//绑定二级菜单
        {
            detail = new BDetailMenus ();
            this.rptSecond.DataSource = detail.SelectDetailMenus();
            this.rptSecond.DataBind();
        }

        private void BindChangeNews()//绑定轮换新闻
        {
            pic = new BPicInfo ();
            this.NewsRepeater.DataSource = pic.SelectPicInfo("轮换新闻");
            this.NewsRepeater.DataBind();
        }

        private void BindPicLink()//绑定图片链接
        {
            pic = new BPicInfo ();
            this.ImageRepeater.DataSource = pic.SelectPicInfo("链接图片");
            this.ImageRepeater.DataBind();
        }

        private void BindLink()//绑定快速链接
        {
            link = new BLinkInfo ();
            this.LinkRepeater.DataSource = link.SelectAllLinkInfo();
            this.LinkRepeater.DataBind();
        }
    }
}